#ifndef TEXTUREMANAGER_CPP
#define TEXTUREMANAGER_CPP

#include "texturemanager.h"

#include <iostream>

CTextureManager::CTextureManager()
{
}

CTextureManager::~CTextureManager()
{
}

void CTextureManager::loadAllTexture()
{
    std::cout << "Loading textures..." << std::endl;
    // on se crée une image temporaire
    sf::Image image_tampon;

    if ( !image_tampon.LoadFromFile("img/suzanne.png"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    m_texture_map["CPlayer"] = image_tampon;

    if ( !image_tampon.LoadFromFile("img/pruzina.tga"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    m_texture_map["snake"] = image_tampon;

    if ( !image_tampon.LoadFromFile("img/sky_background.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    m_texture_map["sky"] = image_tampon;

    if ( !image_tampon.LoadFromFile("img/grass.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    m_texture_map["ground"] = image_tampon;

    if ( !image_tampon.LoadFromFile("img/star.png"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    m_texture_map["star"] = image_tampon;

    // ICI ON CHARGE LES TEXTURES DES CASES

    if ( !image_tampon.LoadFromFile("img/rock043.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_boxes[2]=image_tampon;

    if ( !image_tampon.LoadFromFile("img/crate21.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_boxes[3]=image_tampon;

    // on charge les texture de la case dans la map
    std::pair<int,int> pair_tampon;

    pair_tampon = std::make_pair(2,0);
    if ( !image_tampon.LoadFromFile("img/checker03.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_tiles[pair_tampon]=image_tampon;

    pair_tampon = std::make_pair(2,1);
    if ( !image_tampon.LoadFromFile("img/sand010.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_tiles[pair_tampon]=image_tampon;

    pair_tampon = std::make_pair(3,0);
    if ( !image_tampon.LoadFromFile("img/tiles_ctf01_2.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_tiles[pair_tampon]=image_tampon;

    pair_tampon = std::make_pair(3,1);
    if ( !image_tampon.LoadFromFile("img/tiles_ctf02b.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_tiles[pair_tampon]=image_tampon;

    pair_tampon = std::make_pair(3,2);
    if ( !image_tampon.LoadFromFile("img/tiles_ctf02r.jpg"))
        std::cerr << "N'a pas pu charger la texture" << std::endl;
    map_texture_tiles[pair_tampon]=image_tampon;

    std::cout << "Textures loaded!" << std::endl;
}

void CTextureManager::bindTexture(const std::string& mesh_name)
{
    m_texture_map.find(mesh_name)->second.Bind();
}

#endif //TEXTUREMANAGER_CPP
